package com.fitness.fitness.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fitness.fitness.convertor.EquipmentConvertor;
import com.fitness.fitness.mapper.EquipmentMapper;
import com.fitness.fitness.modal.resource.dto.EquipmentDto;
import com.fitness.fitness.modal.resource.entity.Equipment;
import com.fitness.fitness.modal.resource.params.EquipmentPageQueryParams;
import com.fitness.fitness.modal.resource.vo.EquipmentVO;
import com.fitness.fitness.service.IEquipmentService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class EquipmentServiceImpl extends ServiceImpl<EquipmentMapper,Equipment> implements IEquipmentService {

    private final EquipmentConvertor equipmentConvertor;

    @Override
    public Page<EquipmentVO> getEqupmentPage(EquipmentPageQueryParams queryParams) {// 参数构建
        int pageNum = queryParams.getPageNum();
        int pageSize = queryParams.getPageSize();
        Page<Equipment> page = new Page<>(pageNum, pageSize);

        Page<Equipment> retPage = this.baseMapper.getEqupmentPage(page,queryParams);

        return equipmentConvertor.entity2vo(retPage);
    }

    @Override
    public boolean addEquipment(EquipmentDto equipmentDto) {
        return save(equipmentConvertor.dto2Entity(equipmentDto));
    }

    @Override
    public boolean updateEquipment(EquipmentDto equipmentDto) {
        return updateById(equipmentConvertor.dto2Entity(equipmentDto));
    }


}
